<template>
  <a-table :columns="columns" :data-source="data" :pagination="false">
    <template #end_time="end_time">
      {{ end_time | dateFormat('YYYY-MM-DD HH:mm:ss') }}
    </template>
    <template #opinion="opinion">
      {{ opinionStatus[opinion] || '/' }}
    </template>
  </a-table>
</template>

<script>
import { getExaRecord } from '@/api/flow/work'
import props from './props'

const columns = [
  {
    title: '序号',
    dataIndex: 'index',
    key: 'index',
    align: 'center',
    width: 100,
    customRender: (text, record, index) => `${index + 1}`,
  },
  {
    title: '步骤',
    dataIndex: 'steps',
    align: 'center',
  },
  {
    title: '操作人',
    dataIndex: 'username',
    ellipsis: true,
    align: 'center',
  },
  {
    title: '意见',
    dataIndex: 'opinion',
    ellipsis: true,
    align: 'center',
    scopedSlots: { customRender: 'opinion' },
  },
  {
    title: '结束时间',
    dataIndex: 'end_time',
    ellipsis: true,
    align: 'center',
    scopedSlots: { customRender: 'end_time' },
  },
]

export default {
  mixins: [props],

  data () {
    return {
      columns,
      data: [],

      opinionStatus: {
        '1': '提交',
        '2': '通过',
        '3': '拒绝',
        '4': '开',
        '5': '关',
        '6': '成功',
        '7': '失败',
        '8': '取消订单',
        '9': '手动拨款',
      },
    }
  },

  created () {
    this.getExaRecord()
  },

  methods: {
    getExaRecord () {
      return new Promise((resolve, reject) => {
        getExaRecord(this.tid)
          .then(data => {
            this.data = data
            resolve(data)
          })
          .catch(error => {
            reject(error)
          })
      })
    },
  },
}
</script>
